const express = require('express')
const fs = require('fs')
const { json } = require('express')
const template = require('art-template')

const app = express()
app.get('/', (req, res) => {
  // 获取模板
  const templateStr = fs.readFileSync('./index.html', 'utf-8')

  // 获取数据
  let data = fs.readFileSync('./data.json', 'utf-8')
  data = JSON.parse(data)

  // 结合模板和数据
  const html = template.render(templateStr, {
    title: data.title,
    posts: data.posts
  })

  res.send(html)
})

app.listen(3000, () => console.log('runing...'))
